package eteam.aps.systemservice.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig {
    /*
    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }
    */

    /*
    public class GateWayMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
        GateWayMappingJackson2HttpMessageConverter() {
            List<MediaType> mediaTypes = new ArrayList<>();
            mediaTypes.add(MediaType.valueOf(MediaType.TEXT_HTML_VALUE + ";charset=UTF-8"));
            mediaTypes.add(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8"));
            setSupportedMediaTypes(mediaTypes);
        }
    }
    */

//    @Bean("requestInterceptor")
//    public RequestInterceptor requestInterceptor() {
//        //防止feign远程调用丢失请求头数据
//        return new RequestInterceptor() {
//            @SneakyThrows
//            @Override
//            public void apply(RequestTemplate requestTemplate) {
//                ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//                if (requestAttributes != null) {
//                    HttpServletRequest request = requestAttributes.getRequest();
//                    request.setCharacterEncoding("utf-8");
//                    String userInfo = request.getHeader(name:"user");
//                    if (StrUtil.isNotBlank(userInfo)) {
//                        // 同步请求
//                        requestTemplate.header(name:"user", userInfo);
//                    }
//                }
//            }
//        };
//    }
}
